package forums.service;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.security.RolesAllowed;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import forums.model.Forum;

/*
 * Author       :       Willie Wheeler and John Wheeler
 * Book         :       'Spring In Practice' [Book written by Willie Wheeler and John Wheeler]
 */
@Component
public class ForumListFilter {
	
	@Autowired
	private ForumFilter forumFilter;
	
	public void setForumFilter(ForumFilter forumFilter) {
		this.forumFilter = forumFilter;
	}
	
	/**
	 * <p>
	 * Returns a copy of the original list of forums, with unauthorized
	 * forums and messages removed.
	 * </p>
	 * 
	 * @param origList
	 * @return
	 */
	@RolesAllowed({ "IS_AUTHENTICATED_ANONYMOUSLY", "AFTER_ACL_COLLECTION_READ" })
	public List<Forum> filter(List<Forum> origList) {
		List<Forum> copyList = new ArrayList<Forum>();
		for (Forum origForum : origList) {
			copyList.add(forumFilter.filter(origForum));
		}
		return copyList;
	}

}
